package emulator.unittest.hardware.nmos6502.timing;


import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;

public class AbsoluteYTest {

	@Test
	public void testADC() throws EmulatorException
	{
		int opcode = 0x79;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testAND() throws EmulatorException
	{
		int opcode = 0x39;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testCMP() throws EmulatorException
	{
		int opcode = 0xD9;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testEOR() throws EmulatorException
	{
		int opcode = 0x59;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testLDA() throws EmulatorException
	{
		int opcode = 0xB9;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testLDX() throws EmulatorException
	{
		int opcode = 0xBE;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testORA() throws EmulatorException
	{
		int opcode = 0x19;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}
	
	@Test
	public void testSBC() throws EmulatorException
	{
		int opcode = 0xF9;
		assertEquals(4, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}

	@Test
	public void testSTA() throws EmulatorException
	{
		int opcode = 0x99;
		assertEquals(5, getCycles(opcode, false));
		assertEquals(5, getCycles(opcode, true));
	}

	private int getCycles(int opcode, boolean cross_page) throws EmulatorException
	{
		TimingTestBase test_base = new TimingTestBase();
		test_base.setRegisters(0, 0, (cross_page ? 0xC0 : 0), 0);
		test_base.setCommand(0, opcode, 0x44, 0);
		test_base.execute();
		return test_base.getElapsedCycles();
	}
}
